package com.cuzofu.fs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cuzofu.fs.common.PageUtils;
import com.cuzofu.fs.common.Query;
import com.cuzofu.fs.dao.ProjectDao;
import com.cuzofu.fs.entity.ProjectEntity;
import com.cuzofu.fs.service.MajorService;
import com.cuzofu.fs.service.ProjectService;
import com.cuzofu.fs.vo.ProjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Map;


@Service("projectService")
public class ProjectServiceImpl extends ServiceImpl<ProjectDao, ProjectEntity> implements ProjectService {

    @Autowired
    private MajorService majorService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProjectVO> page = this.baseMapper.queryProjectPage(
                new Query<ProjectVO>().getPage(params),
                new QueryWrapper<ProjectVO>()
        );

        return new PageUtils(page);
    }

    @Override
    public ProjectVO queryById(String id) {
        ProjectVO projectVO = this.baseMapper.queryProjectById(id);
        projectVO.setUnitList(this.baseMapper.queryUnitListByPid(id));
        return projectVO;
    }

    @Override
    @Transactional
    public boolean deleteProject(String[] ids) {

        this.removeByIds(Arrays.asList(ids));

        return true;
    }

}